home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 526-550 / disk_550 / icalc / stat.icalc < prev    next >
Text File  |  1992-05-06  |  1KB  |  77 lines

  1. #    
  2. #    stat.icalc
  3. #
  4. #    Simple one-variable statistical analysis
  5. #    (finds mean, standard deviations etc.)
  6. #
  7. #    Demonstrates use of multi() special function.
  8. #
  9. #
  10. #
  11. #    variables used:
  12. #
  13. #        st_n        number of data
  14. #
  15. #        st_sum        sum of data
  16. #
  17. #        st_ss        sum of squares
  18. #
  19. #
  20. #
  21. #    functions defined:
  22. #
  23. #        statistical reset:    scl()
  24. #
  25. #        single data entry:    d(x)
  26. #
  27. #        multiple data entry:    fd(x,freq)
  28. #
  29. #        single data deletion:    deld(x)
  30. #
  31. #        multiple data deletion:    delfd(x,freq)
  32. #
  33. #        mean of sample:        mean()
  34. #
  35. #        popn. standard dev:    psd()
  36. #
  37. #        sample standard dev:    ssd()
  38. #
  39. #
  40. #
  41. #    Martin W Scott, August 1991
  42. #
  43. silent
  44.  
  45. # Create statistical variables
  46. st_n = st_sum = st_ss = 0
  47.  
  48. # Clear statistical variables
  49. func scl() = (st_n = st_sum = st_ss = 0)
  50.  
  51. #data entry
  52. func d(x) = multi(st_sum = st_sum + x,\
  53.           st_ss = st_ss + sqr(x), \
  54.           st_n = st_n+1)
  55.  
  56. func fd(x,freq) = multi(st_sum = st_sum + freq*x, \
  57.             st_ss = st_ss + freq*sqr(x), \
  58.             st_n = st_n+freq )
  59.  
  60. #data deletion
  61. func deld(x) = fd(x,-1)
  62. func delfd(x,freq) = fd(x,-freq)
  63.  
  64.  
  65. #sample statistics
  66.  
  67. # -- sample standard deviation
  68. func ssd() = sqrt((st_ss - sqr(st_sum)/st_n)/st_n)
  69.  
  70. # -- population standard deviation
  71. func psd() = sqrt((st_ss - sqr(st_sum)/st_n)/(st_n-1))
  72.  
  73. # -- sample mean
  74. func mean() = st_sum / st_n
  75.  
  76. verbose
  77.